package com.wufun.overseas.joystick.map;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

/**
 * Created by xiet on 2015/8/26.
 */
public enum KeyCodes {
    KEY_UP(0x1 << 0),//
    KEY_DOWN(0x1 << 1),
    KEY_LEFT(0x1 << 2),
    KEY_RIGHT(0x1 << 3),

    KEY_A(0x1 << 4),//
    KEY_B(0x1 << 5),
    KEY_C(0x1 << 6),//X
    KEY_D(0x1 << 7),//Y

    KEY_E(0x1 << 8),//
    KEY_F(0x1 << 9),//
    KEY_L1(0x1 << 10),
    KEY_R1(0x1 << 11),//
    KEY_L2(0x1 << 12),
    KEY_R2(0x1 << 13),

    KEY_1(0x1 << 14),
    KEY_2(0x1 << 15),
    KEY_3(0x1 << 16),
    KEY_4(0x1 << 17),

    KEY_UP1(0x1 << 18),
    KEY_DOWN1(0x1 << 19),
    KEY_LEFT1(0x1 << 20),
    KEY_RIGHT1(0x1 << 21),

    KEY_START(0x1 << 22),
    KEY_SELECT(0x1 << 23),

    KEY_PRESS(0x1 << 25),
    KEY_SP0(0x1 << 26),
    KEY_SP1(0x1 << 27),
    KEY_SP2(0x1 << 28),
    KEY_SP3(0x1 << 29),
    KEY_SP4(0x1 << 30);

    private int value;

    KeyCodes(int value) {
        this.value = value;
    }

    public int value() {
        return this.value;
    }

    public static List<KeyCodes> find(int value) {
        List<KeyCodes> ret = new ArrayList<KeyCodes>();

        KeyCodes[] keyCodes = KeyCodes.values();
        List<KeyCodes> list = Arrays.asList(keyCodes);
        Iterator<KeyCodes> iterator = list.iterator();
        while (iterator.hasNext()) {
            KeyCodes keyCode = iterator.next();
            if ((keyCode.value() & value) != 0) {
                ret.add(keyCode);
            }
        }

        return ret;
    }

    public static HashMap<Integer, String> getMap() {
        HashMap<Integer, String> ret = new HashMap<Integer, String>();
        KeyCodes[] keyCodes = KeyCodes.values();
        for (int i = 0; i < keyCodes.length; i++) {
            KeyCodes keyCode = keyCodes[i];
            ret.put(keyCode.value(), keyCode.name());
        }
        return ret;
    }
}
